
<html>

<head>
    <include file="public@head" title="注册用户-用户列表"/>
</head>

<body class="layui-layout-admin">
<include file="public@header"/>
<include file="public@side"/>
<div class="layui-body">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a href="{:url('tdadmin/index/index')}">主页</a>
        <a href="{:url('tdadmin/user/index')}">教师管理</a>
        <a><cite>教师管理</cite></a>
    </div>
    <div class="layui-fluid pdt10">
        <div class="layui-card">
            <div class="layui-card-header">
                用户管理
                <a href="{:url('add')}" class="layui-btn fr"><i class="layui-icon">&#xe61f;</i>添加教师</a>
                <a href="{:url('insert')}" class="layui-btn fr"><i class="layui-icon">&#xe61f;</i>批量添加</a>
                <a href="/upload/file/%E8%80%81%E5%B8%88%E6%89%B9%E9%87%8F%E5%AF%BC%E5%85%A5%E6%A8%A1%E6%9D%BF.xlsx"><span style="color: #ff0000;">模板下载</span></a>

            </div>
            <div class="layui-card-body">
                <div class="listsTable layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="phone" placeholder="手机号" autocomplete="on" class="layui-input">
                        </div>
                        <button class="layui-btn" data-type="reload">筛选</button>
                    </div>
                </div>

                <table class="layui-hide table-center" id="lists" lay-filter="lists"></table>

                <script type="text/html" id="imgTpl">
                    <img src="{{d.head_img}}" height="42">
                </script>

                <script type="text/html" id="statusTpl">
                    <input type="checkbox" lay-skin="switch" {{ d.status==1
                           ? 'checked' : '' }} lay-filter="switch" data-url="{:url('doSwitch')}?id={{d.id}}&field=status" lay-text="显示|隐藏">
                                   <input type="checkbox" lay-skin="switch" {{ d.show_home==1
                           ? 'checked' : '' }} lay-filter="switch" data-url="{:url('doSwitch')}?id={{d.id}}&field=show_home" lay-text="显示|隐藏">
                </script>

                <script type="text/html" id="barLists">
                    <a class="layui-btn layui-btn-sm" href="{:url('/index/people/talentsdetail')}?id={{d.id}}"><i class="layui-icon layui-icon-list"></i>查看</a>
                    <a class="layui-btn layui-btn-sm" href="{:url('edit')}?id={{d.id}}"><i class="layui-icon layui-icon-list"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>
</div>
<include file="public@scripts"/>
<script>
        
    var table = layui.table;
    table.render({
        elem: '#lists',
        even: true,
        id: 'listsReload',
        url: "{:url('getUsers')}",
        cols: [[
            {field: 'id', title: 'ID', align: 'center', width: 80}
            , {field: 'real_name', title: '姓名', width: 150}
            , {field: 'phone', title: '联系方式',  width: 120}
            , {field: 'teacher_no', title: '工号',  width: 120}
            ,{field: 'status', title: '状态/首页显示', width: 200, templet: '#statusTpl', unresize: true, align: 'center'},
			,{ fixed: 'right', title: '操作', align: 'center',width:250, toolbar: '#barLists' }
        ]],
        page: true
    });

    var active = {
        reload: function () {
            var mobile = $('input[name="mobile"]').val();

            table.reload('listsReload', {
                where: {
                    key: {
                        mobile: mobile
                    }
                }
            });
        }
    };

    $('.listsTable .layui-btn').on('click', function () {
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    table.on('tool(lists)', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
        var tr = obj.tr;
        console.log(data)
        if (layEvent === 'delete') {
            layer.confirm('您将彻底删除【' + data.real_name + '】！', function (index) {
                obj.del();
                layer.close(index);
                $.ajax({
                    type: "post",
                    data: {id: data.id},
                    url: "{:url('delTeacher')}",
                    success: function (result) {

                        if (result.code == 1) {
                            layer.msg(result.msg, {icon: 6, time: 1000}, function (index) {
                                layer.close(index);
                                window.location.reload();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 5, time: 800}, function (index) {
                                layer.close(index);
                            });
                            return false;
                        }
                    }
                });
            });
        }
    });
</script>
</body>

</html>
